﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestsBase.lib;

namespace OnlineTest
{
    public partial class Result : Page
    {
        private TestDatabase Quiz;

        protected void Page_Load(object sender, EventArgs e)
        {
            PlaceHolder1.Controls.Clear();
            Quiz = (TestDatabase) Session["Quiz"];

            if (Quiz == null)
            {
                Response.Redirect("Default.aspx");
                return;
            }

            if (Request["do"] == "Reset")
            {
                Session["Quiz"] = null;
                Response.Redirect("Default.aspx");
                return;
            }

            Label msg = new Label();
            int summ = 0;
            foreach (Test test in Quiz.Tests)
            {
                summ += test.Result;
            }
            msg.Text = string.Format("Gained '{0}' scores for '{1}' tests", summ, Quiz.Tests.Count);
            PlaceHolder1.Controls.Add(msg);


            HyperLink reset = new HyperLink();
            reset.Text = "Reset";
            reset.NavigateUrl = "Result.aspx?do=Reset";
            reset.ID = "resetBtn";
            PlaceHolder1.Controls.Add(reset);
        }
    }
}